package list;
import iterators.*;

public class List implements AbstractStructure
{
	protected Element first, last;
	protected int size;
	
	public List()
	{
		first=last=null;
		size=0;
	}
	
	public Element getFirst()
	{
		return first;
	}
	
	public void setFirst ( Element first)
	{
		this.first=first;
	}
	public Element getLast()
	{
		return last;
	}
	public void setLast(Element last)
	{
		this.last=last;
	}
	public int getSize()
	{
		return size;
	}
	public void setSize(int size)
	{
		this.size=size;
	}
	public void Append(Object obj)
	{
		Element _new = new Element(obj);
		if( first ==null) //adaugarea primului element
			first=_new;
		if(last !=null)//adaugarea oricarui element diferit de primul
			last.next=_new;
		    last=_new;
		    size++;	
	}
	
	public int Count()
	{
		return size;
	}
	
	public Iterator CreateIterator()
	{
		return new ListIterator(this);
	}
	public void Remove ( Object obj)
	{
		//search for the object that must be remove
		Element q1=first,q2=first;
		while ( q2 != null)
		{
			if( q2.data.equals(obj)) 
			{
				//we find it
				if( q2 != first)
					q1.next= q2.next;
				else
					first = first.next;
				return;
			}
			q1 =q2;
			q2=q1.next;	
		}
	}
}
